package com.suning.sawp.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.intf.store.StoreInfoService;
import com.suning.sawp.web.exception.MyGsonView;

@Controller
@RequestMapping("/region")
public class RegionController extends DjBaseController{
    
    @Autowired
    StoreInfoService storeInfoService;
    
    @RequestMapping("/queryAllRegion.do")
    public MyGsonView queryAllRegion(){
        MyGsonView result = createGsonView();
        result.addStaticAttribute("regions", storeInfoService.queryAllRegions());
        return result;
    }
    
    @RequestMapping("/queryStroeByRegionCode.do")
    public MyGsonView queryStroeByRegionCode(String regionCode){
        
        MyGsonView result = createGsonView();
        if(StringUtils.isBlank(regionCode)){
            setErrorMsg(result, ErrorCodeConstants.ERR_0005);
            return result;
        }
        result.addStaticAttribute("storeInfos", storeInfoService.queryStoresByRegionCode(regionCode));
        return result;
    }
    
}
